﻿using System;
using System.Net;
using System.Net.Sockets;
using System.Web;

namespace Medora.Core
{
    public class Utils
    {
        public static string ApplicationName{
            get { return System.Web.Security.Membership.ApplicationName; }
        }
        
       public static Guid UserController(string name)
        {
           
                try
                {
                    return (Guid)System.Web.Security.Membership.GetUser(name).ProviderUserKey;
                }
                catch (Exception e)
                {
                   return new Guid("1852FA8A-EF02-4C67-A31C-D9ADFF874DCD");
                }


        }

        public static string IP
        {
            get
            {
               IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
               string localIP = "not defined";
            
                foreach (IPAddress ip in host.AddressList)
                {
                    if (ip.AddressFamily == AddressFamily.InterNetwork)
                    {
                        localIP = ip.ToString();
                    }
                }
                return localIP;
            }
            
        }

        public static string WebRoot
        {
            get
            {
                try
                {
                    return HttpContext.Current.Request.PhysicalApplicationPath;
                }
                catch
                {
                    return Environment.CurrentDirectory;
                }
                
            }
        }

        
        
    }
}
